import 'package:animal/network/api.dart';
import 'package:animal/ui/login/NWApi.dart';
import 'package:animal/utils/RuleUtils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

class ForGetPwdController extends GetxController{
  //手机号码
  TextEditingController phoneController = TextEditingController();
  //验证码
  TextEditingController codeController = TextEditingController();
  //密码
  TextEditingController pwdController = TextEditingController();

  ///找回密码
  void pwdReset(){
    if (!phoneController.text.isNotEmpty) {
      SmartDialog.showToast("请输入手机号码", alignment: Alignment.center);
      return;
    }
    if (RuleUtils().checkStringRule(RuleType.phone, phoneController.text, null) != null) {
      SmartDialog.showToast("手机号码错误，请重新输入", alignment: Alignment.center);
      return;
    }
    if (!pwdController.text.isNotEmpty) {
      SmartDialog.showToast("请输入密码", alignment: Alignment.center);
      return;
    }
    if (!codeController.text.isNotEmpty) {
      SmartDialog.showToast("验证码不能为空");
      return;
    }
    if (pwdController.text.length < 6) {
      SmartDialog.showToast("密码长度不能小于6位", alignment: Alignment.center);
      return;
    }
    var putData = {
      "code":codeController.text,
      "mobile":phoneController.text,
      "pwd":pwdController.text,
    };
    HttpManager().post(NWApi.userLoginResetPwd,queryParameters: putData).listen((value) {
      SmartDialog.showToast("修改成功");
    },onError: (err){
      debugPrint(err.message);
    });
  }
}